#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/device.h>
#include <linux/of.h>
#include <linux/uaccess.h>
#include <linux/platform_device.h>

// 定义 release 回调函数
static void my_device_release(struct device *dev) 
{
    printk(KERN_INFO "my_device_release: Releasing device\n");
    // 在这里释放设备对象所占用的资源
}


static struct platform_device my_virtual_device = {
    .name = "my_virtual_device",  // 设备名称
    .id = -1,                     // 设备ID，-1 表示无ID
	.dev = {
		.release = my_device_release ,
	},
};
#define PRT printk("HanJ %s %s %d\n" ,__FILE__ , __func__ ,__LINE__ )
static int __init my_device_init(void) {
    printk(KERN_INFO "my_device_init: Registering platform device\n");
	// 为设备对象设置 release 回调函数
	//my_virtual_device.dev.release = my_device_release;

	platform_device_register(&my_virtual_device);
	PRT ; PRT ;
    return 0;
}

static void __exit my_device_exit(void) {
    printk(KERN_INFO "my_device_exit: Unregistering platform device\n");
    platform_device_unregister(&my_virtual_device);
	PRT;PRT ;
}

module_init(my_device_init);
module_exit(my_device_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Your Name");
MODULE_DESCRIPTION("A simple platform device example");
MODULE_VERSION("0.1");

